package org.mch.func.db.tool;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;

import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.mch.biz.ui.FuncEvent;
import org.mch.biz.ui.FuncPanel;
import org.mch.swingm.core.MButton;
import org.mch.swingm.core.MListModel;

public class DBToolPanel extends FuncPanel {
	private static final long serialVersionUID = 1L;
	private JSplitPane splitPane;
	private JPanel panel_1;
	private JList<String> list_tableName;
	private MButton button_loadusertable;
	private JLabel lblsql;
	private MButton btnsql;
	private MButton btnbaseeo;
	private MButton btnhibernatevo;
	private MButton btnjavabean;
	private JScrollPane scrollPane_2;
	private RSyntaxTextArea textArea_right;
	private JTabbedPane tabbedPane;
	private JPanel panel_db;
	private MButton btn_clear;
	private JTextField text_wheresql;
	private JScrollPane scrollPane_5;
	private JCheckBox isDeleteSQL;
	private JTextField text_delfield;
	private JTextField textField;
	private MButton btnjpabean;
	private JScrollPane scrollPane;
	private MButton btn_ybj_updatesql;
	private MButton btn_ybj_insertsql;
	private JCheckBox isYbjInsertSqlNotPk;
	private JCheckBox isYbjSqlLower;
	private MButton btn_mybatis_insertsql;
	private MButton btn_mybatis_updatesql;
	private MButton btneasypoi;

	public DBToolPanel() {
		setLayout(new BorderLayout(0, 0));
		add(getSplitPane(), "Center");
	}

	public JSplitPane getSplitPane() {
		if (this.splitPane == null) {
			this.splitPane = new JSplitPane();

			this.splitPane.setRightComponent(getPanel_1());
			this.splitPane.setLeftComponent(getTabbedPane());
			this.splitPane.setDividerLocation(380);
		}
		return this.splitPane;
	}

	public JPanel getPanel_1() {
		if (this.panel_1 == null) {
			this.panel_1 = new JPanel();
			this.panel_1.setLayout(new BorderLayout(0, 0));
			this.panel_1.add(getScrollPane_2_1(), "Center");
		}
		return this.panel_1;
	}

	public JList<String> getList_tableName() {
		if (this.list_tableName == null) {
			this.list_tableName = new JList<String>();
			this.list_tableName.setModel(new MListModel<String>());
		}
		return this.list_tableName;
	}

	public MButton getButton_loadusertable() {
		if (this.button_loadusertable == null) {
			this.button_loadusertable = new MButton("\u52A0\u8F7D\u6570\u636E\u8868");
			button_loadusertable.setFont(new Font("宋体", Font.PLAIN, 12));
			this.button_loadusertable.setBounds(106, 12, 84, 28);
			this.button_loadusertable.addActionListener(getEvent());
		}
		return this.button_loadusertable;
	}

	public JLabel getLabel_5_1() {
		if (this.lblsql == null) {
			this.lblsql = new JLabel("\u5BFC\u51FASQL\u7684\u6761\u4EF6\uFF1A");
			lblsql.setFont(new Font("宋体", Font.PLAIN, 12));
			this.lblsql.setBounds(10, 313, 97, 15);
		}
		return this.lblsql;
	}

	public MButton getBtnsql() {
		if (this.btnsql == null) {
			this.btnsql = new MButton("SQL");
			this.btnsql.setBounds(166, 337, 97, 28);
			this.btnsql.addActionListener(getEvent());
		}
		return this.btnsql;
	}

	public MButton getBtnbaseeo() {
		if (this.btnbaseeo == null) {
			this.btnbaseeo = new MButton("SuperVO");
			btnbaseeo.setText("BaseEO");
			this.btnbaseeo.setBounds(202, 41, 130, 28);
			this.btnbaseeo.addActionListener(getEvent());
		}
		return this.btnbaseeo;
	}

	public MButton getBtnhibernatevo() {
		if (this.btnhibernatevo == null) {
			this.btnhibernatevo = new MButton("Hibernate");
			this.btnhibernatevo.setBounds(202, 70, 130, 28);
			this.btnhibernatevo.addActionListener(getEvent());
		}
		return this.btnhibernatevo;
	}

	public MButton getBtnjavabean() {
		if (this.btnjavabean == null) {
			this.btnjavabean = new MButton("JavaBean");
			this.btnjavabean.setBounds(202, 12, 130, 28);
			this.btnjavabean.addActionListener(getEvent());
		}
		return this.btnjavabean;
	}

	protected FuncEvent createEvent() {
		return new DBToolEvent(this);
	}

	public JScrollPane getScrollPane_2_1() {
		if (this.scrollPane_2 == null) {
			this.scrollPane_2 = new JScrollPane();
			this.scrollPane_2.setViewportView(getTextArea_right());
		}
		return this.scrollPane_2;
	}

	public RSyntaxTextArea getTextArea_right() {
		if (this.textArea_right == null) {
			this.textArea_right = new RSyntaxTextArea();
			this.textArea_right.setFont(new Font("宋体", Font.PLAIN, 13));
			this.textArea_right.setBorder(new EtchedBorder(0, null, null));
		}
		return this.textArea_right;
	}

	public JTabbedPane getTabbedPane() {
		if (this.tabbedPane == null) {
			this.tabbedPane = new JTabbedPane(1);
			this.tabbedPane.addTab("表对象", null, getPanel_db(), null);
		}
		return this.tabbedPane;
	}

	public JPanel getPanel_db() {
		if (this.panel_db == null) {
			this.panel_db = new JPanel();
			this.panel_db.setLayout(null);

			this.panel_db.add(getBtnbaseeo());
			this.panel_db.add(getBtnhibernatevo());
			this.panel_db.add(getBtnjavabean());
			this.panel_db.add(getBtnsql());
			this.panel_db.add(getButton_loadusertable());
			this.panel_db.add(getLabel_5_1());
			this.panel_db.add(getText_wheresql());
			this.panel_db.add(getIsDeleteSQL());
			this.panel_db.add(getText_delfield());
			this.panel_db.add(getTextField());
			this.panel_db.add(getBtnjpabean());
			this.panel_db.add(getScrollPane());
			panel_db.add(getBtn_ybj_updatesql());
			panel_db.add(getBtn_ybj_insertsql());
			panel_db.add(getIsYbjInsertSqlNotPk());
			panel_db.add(getIsYbjSqlLower());
			panel_db.add(getBtn_mybatis_insertsql());
			panel_db.add(getBtn_mybatis_updatesql());
			panel_db.add(getBtneasypoi());
		}

		return this.panel_db;
	}

	public JTextField getTextField() {
		if (textField == null) {
			textField = new JTextField();
			textField.setBounds(11, 13, 91, 28);
			textField.setColumns(10);
			textField.addActionListener(getEvent());
		}
		return textField;
	}

	public MButton getBtn_Clear() {
		if (this.btn_clear == null) {
			btn_clear = new MButton("\u6E05\u7A7A\u9762\u677F\u6570\u636E");
			btn_clear.setBounds(151, 114, 93, 23);
			btn_clear.setBackground(Color.WHITE);
			btn_clear.setForeground(Color.gray);
			btn_clear.addActionListener(getEvent());
		}
		return this.btn_clear;
	}

	public JTextField getText_wheresql() {
		if (this.text_wheresql == null) {
			this.text_wheresql = new JTextField();
			this.text_wheresql.setBounds(10, 338, 143, 28);
			this.text_wheresql.setColumns(10);
		}
		return this.text_wheresql;
	}

	public JScrollPane getScrollPane_5() {
		if (scrollPane_5 == null) {
			scrollPane_5 = new JScrollPane();
			scrollPane_5.setBounds(10, 10, 284, 141);
		}
		return scrollPane_5;
	}

	public JCheckBox getIsDeleteSQL() {
		if (isDeleteSQL == null) {
			isDeleteSQL = new JCheckBox("Delete SQL");
			isDeleteSQL.setToolTipText("\u9009\u4E2D\u540E\uFF0C\u5C06\u53F3\u8FB9\u6587\u672C\u6846\u4E2D\u8F93\u5165\u7684Field\uFF0C\u751F\u6210\u5220\u9664SQL\uFF01");
			isDeleteSQL.setBounds(10, 371, 97, 23);
		}
		return isDeleteSQL;
	}

	public JTextField getText_delfield() {
		if (text_delfield == null) {
			text_delfield = new JTextField();
			text_delfield.setBounds(110, 372, 148, 21);
			text_delfield.setColumns(10);
		}
		return text_delfield;
	}

	public MButton getBtnjpabean() {
		if (btnjpabean == null) {
			btnjpabean = new MButton("JPA");
			btnjpabean.setBounds(202, 99, 130, 28);
			btnjpabean.addActionListener(getEvent());
		}
		return btnjpabean;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(10, 51, 180, 250);
			scrollPane.setViewportView(getList_tableName());
		}
		return scrollPane;
	}

	public MButton getBtn_ybj_updatesql() {
		if (btn_ybj_updatesql == null) {
			btn_ybj_updatesql = new MButton("JPA");
			btn_ybj_updatesql.setToolTipText("根据选中的表，生成预编译UpdateSQL");
			btn_ybj_updatesql.setText("预编译UpdateSQL");
			btn_ybj_updatesql.setBounds(202, 273, 130, 28);
			btn_ybj_updatesql.addActionListener(getEvent());
		}
		return btn_ybj_updatesql;
	}

	public MButton getBtn_ybj_insertsql() {
		if (btn_ybj_insertsql == null) {
			btn_ybj_insertsql = new MButton("Hibernate");
			btn_ybj_insertsql.setToolTipText("根据选中的表，生成预编译InsertSQL");
			btn_ybj_insertsql.setText("预编译InsertSQL");
			btn_ybj_insertsql.setBounds(202, 244, 130, 28);
			btn_ybj_insertsql.addActionListener(getEvent());
		}
		return btn_ybj_insertsql;
	}

	public JCheckBox getIsYbjInsertSqlNotPk() {
		if (isYbjInsertSqlNotPk == null) {
			isYbjInsertSqlNotPk = new JCheckBox("排除Pk字段");
			isYbjInsertSqlNotPk.setFont(new Font("宋体", Font.PLAIN, 12));
			isYbjInsertSqlNotPk.setSelected(true);
			isYbjInsertSqlNotPk.setToolTipText("生成预编译InsertSQL时，排除主键字段。");
			isYbjInsertSqlNotPk.setBounds(202, 213, 130, 23);
		}
		return isYbjInsertSqlNotPk;
	}

	public JCheckBox getIsYbjSqlLower() {
		if (isYbjSqlLower == null) {
			isYbjSqlLower = new JCheckBox("转换为小写");
			isYbjSqlLower.setFont(new Font("宋体", Font.PLAIN, 12));
			isYbjSqlLower.setToolTipText("生成的预编译SQL（Insert或Update），全小写。不选中，则不动。");
			isYbjSqlLower.setSelected(true);
			isYbjSqlLower.setBounds(202, 186, 130, 23);
		}
		return isYbjSqlLower;
	}

	public MButton getBtn_mybatis_insertsql() {
		if (btn_mybatis_insertsql == null) {
			btn_mybatis_insertsql = new MButton("Hibernate");
			btn_mybatis_insertsql.setToolTipText("根据选中的表，生成MyBatis对应的InsertSQL");
			btn_mybatis_insertsql.setText("MyBatisInsertSQL");
			btn_mybatis_insertsql.setBounds(10, 400, 143, 28);
			btn_mybatis_insertsql.addActionListener(getEvent());
		}
		return btn_mybatis_insertsql;
	}

	public MButton getBtn_mybatis_updatesql() {
		if (btn_mybatis_updatesql == null) {
			btn_mybatis_updatesql = new MButton("JPA");
			btn_mybatis_updatesql.setToolTipText("根据选中的表，生成MyBatis对应的UpdateSQL");
			btn_mybatis_updatesql.setText("MyBatisUpdateSQL");
			btn_mybatis_updatesql.setBounds(10, 429, 143, 28);
			btn_mybatis_updatesql.addActionListener(getEvent());
		}
		return btn_mybatis_updatesql;
	}

	public MButton getBtneasypoi() {
		if (btneasypoi == null) {
			btneasypoi = new MButton("JPA");
			btneasypoi.setToolTipText("EasyPOI中的JavaBean");
			btneasypoi.setText("EasyPOIEO");
			btneasypoi.setBounds(202, 128, 130, 28);
			this.btneasypoi.addActionListener(getEvent());
		}
		return btneasypoi;
	}
}